#ifndef BLLCONTROLLER_H
#define BLLCONTROLLER_H

#include <QObject>
#include <QMutex>
#include <QMutexLocker>
#include <QtSerialPort/qserialport.h>
#include <QThread>
#include "ettadatastruct.h"
#include "controller.h"

class BllController : public QObject
{
    Q_OBJECT
public:
    static BllController * getInstance();
    ~BllController();
    void openSerialPort(const QString & name);
    void sendPortCmd(ComCmd cmd);
    void expResultPass(const HostReply &);
    void expResultFail(const HostReply &);
    void queryHostVersion();

    void setInstrumentStauts(const Status &status);
    Status instrumentStatus();

signals:
    void openSerialPortSignal(const QString & name);
    void sendPortCmdSignal(ComCmd cmd);
    void startPostSignal();
    void progressChangeSignal(int val);
    void expResultPassSignal(const HostReply &);
    void expResultFailSignal(const HostReply &);
    //self check
    void selfCheckResultPassSignal(const HostReply &);
    void selfCheckResultFailSignal(const HostReply &);
    //pwd and flw check
    void pwdflwCheckResultSignal(const HostReply &);
    //SHK_Result
    void shkCheckResultSignal(const HostReply &);
    //Start Experiment
    void experimentStartSignal(const HostReply &);

    // host version
    void hostVersionSignal(const QString &);

    // led
    void lightLedSignal(const LedType &);

    // liquid detected
    void liquidDetectedSignal();

    // motor calibrate done
    void motorCalibDoneSignal(const HostReply &);

public slots:
    //start power on self test signal
    void startPost();
    void dataReceivedSlot(QString data);

private:
    explicit BllController(QObject *parent = nullptr);

private:
    static BllController * instance;
    Controller * ctrlSerial;
    QThread * ctrlThread;
    bool isOpenPort;
    Status curStatus;
};

#endif // BLLCONTROLLER_H
